Skip to content

Conversation

@shin19991207
Copy link
Member

What does this PR do?

Meta-validate the referenced schema of a YAML file against the correct meta-schema based on its $schema value.

This change support meta-validation for:

  • draft-04
  • draft-07
  • draft 2019-09
  • draft 2020-12

What issues does this PR fix or reference?

This PR replaces the hyperjump-based schema meta-validation approach in #1115 with AJV (we already depend on AJV in this project and AJV can validate JSON Schema drafts).

This improves schema meta-validation and is complementary to (but not a prerequisite for) the broader work tracked in #856 to support newer-draft instance validation.

Is it tested? How?

Added automated tests covering draft-specific meta-validation failures for each draft version supported.

Manually verified using the following JSON schemas (create a YAML file containing just the number 1 and point it to each schema):

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "number",
  "minimum": 5,
  "exclusiveMinimum": 5
}
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "number",
  "minimum": 5,
  "exclusiveMinimum": true
}
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$defs": {
    "foo": {
      "type": "object",
      "properties": {
        "bar": { "type": ["foo", "bar"] }
      }
    }
  }
}
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number",
  "prefixItems": "foo"
}

@shin19991207 shin19991207 self-assigned this Jan 12, 2026
@shin19991207 shin19991207 moved this to Pending review in Java Tooling Jan 12, 2026

// load JSON Schema 07 def to validate loaded schemas
// eslint-disable-next-line @typescript-eslint/no-var-requires
const jsonSchema04 = require('ajv-draft-04/dist/refs/json-schema-draft-04.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error

Require statement not part of import statement.

// eslint-disable-next-line @typescript-eslint/no-var-requires
const jsonSchema04 = require('ajv-draft-04/dist/refs/json-schema-draft-04.json');
const jsonSchema2019 = require('ajv/dist/refs/json-schema-2019-09/schema.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error

Require statement not part of import statement.
const jsonSchema04 = require('ajv-draft-04/dist/refs/json-schema-draft-04.json');
const jsonSchema2019 = require('ajv/dist/refs/json-schema-2019-09/schema.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const jsonSchema2020 = require('ajv/dist/refs/json-schema-2020-12/schema.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error

Require statement not part of import statement.
@coveralls
Copy link

coveralls commented Jan 12, 2026

Coverage Status

coverage: 83.677% (+0.02%) from 83.653%
when pulling 511c5c6 on shin19991207:chang-patch-1
into a38caf0 on redhat-developer:main.

Signed-off-by: Morgan Chang <[email protected]>
then?: JSONSchemaRef;
else?: JSONSchemaRef;

// schema draft 2019-09
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly needed for this change, but I'm okay with adding it now, since we'll need to do it eventually.

Copy link
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks, Morgan!

@datho7561 datho7561 added this to the 1.20.0 milestone Jan 12, 2026
@datho7561 datho7561 merged commit 769a8f7 into redhat-developer:main Jan 12, 2026
3 of 4 checks passed
@github-project-automation github-project-automation bot moved this from Pending review to Done in Java Tooling Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants